from tools import get_llm
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
from langchain_core.messages import HumanMessage


@tool
def weather(city):
    '''
    查询城市天气
    :param city:
    :return:
    '''
    return '天气真好'


@tool
def get_city_info(city):
    '''
    查询城市相关信息
    :param city:
    :return:
    '''
    template = ChatPromptTemplate(
        [
            ('human', '我想去{city}，请推荐一下有什么好玩的地方'),
            ('system', '你是一名优秀的导游，根据用户信息回答城市相关特色')
        ]
    )
    chain = template | get_llm()
    return chain.invoke({'city': city}).content


_llm = get_llm()

agent = create_react_agent(_llm, [get_city_info, weather])
_r = agent.invoke({
    "messages": [
        HumanMessage("我想去成都玩可以推荐一下吗")
    ]
})
print(_r['messages'][-1].content)
